//
//  DatePickerView.m
//  LiveStar
//
//  Created by 漪珊 on 2016/12/16.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "DatePickerView.h"
@interface DatePickerView()
@end
@implementation DatePickerView

- (instancetype)initWithFrame:(CGRect)frame DateMode:(UIDatePickerMode)mode {
    if ([super initWithFrame:frame]) {
        self.datePicker.datePickerMode = mode;
        [self addSubview:self.datePicker];
    }
    return self;
}
- (UIDatePicker *)datePicker {
    if (!_datePicker) {
        _datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, kSCREEN_WIDTH, 260)];
        _datePicker.backgroundColor = [UIColor whiteColor];
        _datePicker.date = [NSDate date];
        NSLocale *locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh-Hans"];
        _datePicker.locale = locale;

        UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, 40)];
        toolBar.backgroundColor = [UIColor blackColor];
        toolBar.autoresizingMask =  UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
    
        UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(actionCancel:)];
        UIBarButtonItem *confirmItem = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(actionDone:)];
        UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        space.width = kSCREEN_WIDTH - 100;
        [toolBar setItems:[NSArray arrayWithObjects:cancelItem,space,confirmItem,nil]];
        [self addSubview:toolBar];
        [self addSubview:_datePicker];
    }
    return _datePicker;
}


//取消
- (void)actionCancel:(UIBarButtonItem *)item {
    if (self.DateSelected) {
        self.DateSelected(@"取消");
    }
}
//完成
- (void)actionDone:(UIBarButtonItem *)item {
    if (self.DateSelected) {
        self.DateSelected(@"完成");
    }
}


@end
